package com.myzl.web.controller.coal;

import com.myzl.coal.domain.Device;
import com.myzl.coal.service.IDeviceService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 设备表Controller
 *
 * @author myzl
 * @date 2022-09-01
 */
@RestController
@RequestMapping("/coal/device")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备表列表
     */
    @PreAuthorize("@ss.hasPermi('coal:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /**
     * 导出设备表列表
     */
    @PreAuthorize("@ss.hasPermi('coal:device:export')")
    @Log(title = "设备表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Device device)
    {
        List<Device> list = deviceService.selectDeviceList(device);
        ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class);
        util.exportExcel(response, list, "设备表数据");
    }

    /**
     * 获取设备表详细信息
     */
    @PreAuthorize("@ss.hasPermi('coal:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(deviceService.selectDeviceById(id));
    }

    /**
     * 新增设备表
     */
    @PreAuthorize("@ss.hasPermi('coal:device:add')")
    @Log(title = "设备表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Device device)
    {
        return toAjax(deviceService.insertDevice(device));
    }

    /**
     * 修改设备表
     */
    @PreAuthorize("@ss.hasPermi('coal:device:edit')")
    @Log(title = "设备表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Device device)
    {
        return toAjax(deviceService.updateDevice(device));
    }

    /**
     * 删除设备表
     */
    @PreAuthorize("@ss.hasPermi('coal:device:remove')")
    @Log(title = "设备表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(deviceService.deleteDeviceByIds(ids));
    }

    /**
     * 设备设置密度及速度
     */
    @PreAuthorize("@ss.hasPermi('coal:device:config')")
    @PutMapping(value = "/config")
    public AjaxResult configDensity(@RequestBody Device device){
        return deviceService.configDensity(device);
    }

    /**
     * 查询设备表列表
     */
    @GetMapping("/allList")
    public AjaxResult allList(Device device)
    {
        List<Device> list = deviceService.selectDeviceList(device);
        return AjaxResult.success(list);
    }

    /**
     * 获取设备表详细信息
     */
    @GetMapping(value = "getCamera/{id}")
    public AjaxResult getCamera(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(deviceService.getCamera(id));
    }

    /**
     * 获取筛机及其单台摄像头
     */
    @GetMapping(value = "getSieve/{parentGroupId}")
    public AjaxResult getSieveList(@PathVariable("parentGroupId") String parentGroupId)
    {
        return deviceService.getSieveList(parentGroupId);
    }

    /**
     * 获取设备表详细信息
     */
    @GetMapping(value = "getDeviceParam/{deviceId}/{dictValues}")
    public AjaxResult getDeviceParam(@PathVariable("deviceId") String deviceId,@PathVariable("dictValues") List<String> dictValues)
    {
        return AjaxResult.success(deviceService.getDeviceParam(deviceId,dictValues));
    }

    /**
     * 获取设备表详细信息
     */
    @PostMapping(value = "saveDeviceParam")
    public AjaxResult saveDeviceParam(@RequestBody Map<String,String> deviceParam)
    {
        return deviceService.saveDeviceParam(deviceParam);
    }


    /**
     * 获取设备表详细信息
     */
    @GetMapping(value = "getDevice")
    public AjaxResult getDevice(Device device)
    {
        return AjaxResult.success(deviceService.getDevice(device));
    }

}
